package com.leyou.item.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leyou.common.pojo.PageResult;
import com.leyou.item.mapper.BrandMapper;
import com.leyou.item.pojo.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandService
{
    @Autowired
    private BrandMapper mapper;
    public Brand getBrandById(Long id){
    return mapper.selectByPrimaryKey(id);
    }

    public PageResult<Brand> getBrandsByPage(Integer pageNum, Integer pageSize){
        //1.初始化分页
        PageHelper.startPage(pageNum,pageSize);
        //2.查询数据
        List<Brand> brands = mapper.selectAll();
        //3.创建分页对象，解析返回数据
        PageInfo<Brand> info = new PageInfo<>(brands);
        PageResult<Brand> pageResult = new PageResult<>();
        pageResult.setTotal(info.getTotal());
        pageResult.setTotalPage(info.getPages());
        pageResult.setDatas(info.getList());
        return pageResult;
    }
}

